<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>国省道 - 分成资金添加</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/easyui/themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/easyui/themes/icon.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/buttons.css" />
    <script type="text/javascript" src="${pageContext.request.contextPath}/easyui/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-form.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/easyui/datagrid-detailview.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/easyui/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/util/jquery.cookie.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/YMLib.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/YWLib.js"></script>
    <style type="text/css">
        .table{border: 1px solid #FFE7BA;}
        .table tr{border: 1px solid #FFE7BA;}
        .table tr td{border: 1px solid #FFE7BA;}
        .table tr td input{width: 50px;}
        .table1{border: 1px solid #FFE7BA;}
        .table1 tr{border: 1px solid #FFE7BA;}
        .table1 tr td{border: 1px solid #FFE7BA;}
    </style>
    <script type="text/javascript">
        function loadWhBmbmShNew(id, xmbm, xmnf) {
            $('#' + id).combobox({
                url : '/jxcsxm/shares/getShareTreeByName.do?xmbm='
                    + encodeURI(encodeURI(xmbm))+"&xmnf="+xmnf,
                valueField : 'bmid',
                textField : 'name',
                panelHeight:'auto',
                editable:false,
                multiple:false
            });
        }

        function sumDfzc() {
            var tr = $("tr[name='"+$.cookie("unit")+"']");
            $.each(tr,function(index,item){
                var inputList = $("#"+item.id+" input");
                var dszc1=0;var qxzc1=0;var qtzc1=0;
                dszc1=parseFloat($(inputList[5]).val()==""?0:parseFloat($(inputList[5]).val()));
                qxzc1=parseFloat($(inputList[6]).val()==""?0:parseFloat($(inputList[6]).val()));
                qtzc1=parseFloat($(inputList[7]).val()==""?0:parseFloat($(inputList[7]).val()));
                $(inputList[3]).val(dszc1+qxzc1+qtzc1);
            });
        }

        $(function () {
            $("#nf1").combobox({onSelect:function(record){
                    // loadWhBmbmShNew('jhxdwh', $("#nf1").combobox('getValue'));
                    loadWhBmbmShNew('jhxdwh', parent.parent.YMLib.Var.xmbm, $("#nf1").combobox('getValue'));
             }});

            loadBmbm('nf1','项目年份',new Date().getFullYear());

            loadWhBmbmShNew('jhxdwh', parent.parent.YMLib.Var.xmbm, $("#nf1").combobox('getValue'));

            getFwqTime("dwyf");

            var gydw=$.cookie("unit");
            if(gydw=="36"){
                loadChildGydw("21101360000");
            }else{
                loadChildGydw(gydw);
            }
        });

        function loadChildGydw(gydw){
            $.ajax({
                type:'post',
                async:false,
                url:'/jxcsxm/shares/queryChildGydw.do',
                data:'gydw='+gydw,
                dataType:'json',
                success:function(data){
                    $.each(data,function(index,item){
                        $('#zjdw_table_tbody')
                            .append('<tr name="'+$.cookie("unit")+'" id="'+item.id+'">' +
                                '<td align="center">'+item.name+'</td>' +
                                '<td align="center">' +
                                '<input type="number" width="60" /></td>' +
                                '<td  align="center">' +
                                '<input type="number" width="60" /></td>' +
                                '<td align="center">' +
                                '<input type="number" width="60" /></td>' +
                                '<td align="center">' +
                                '<input readonly type="number" width="60" />' +
                                '<input type="hidden" value="'+item.parent+'"/></td>' +
                                '<td align="center">' +
                                '<input oninput="sumDfzc()" type="number" width="60" /><font color="red"></font></td>' +
                                '<td align="center">' +
                                '<input oninput="sumDfzc()" type="number" width="60" /><font color="red"></font></td>' +
                                '<td align="center"><input oninput="sumDfzc()" type="number" width="60" />' +
                                '<font color="red"></font></td></tr>');
                    });
                }
            });
        }

        function save() {
            if($('#jhxdwh').combo("getValue")==""){alert("请选择计划下达文号");return;}

            var ztz = $("#funds_num").text();
            if (ztz == 0) {
                alert("请点击查询所剩资金！");return;
            }

            if ($("#tbsj").datebox("getValue") == "" || $("#tbsj").datebox("getValue") == null) {
                alert("请选择填报时间！");return;
            }

            var zj = params($.cookie("unit"));

            if (parseInt(zj.ztz) == 0) {
                alert("请认真填写！");
                return;
            }

            if (parseFloat(zj.ztz) > parseFloat(ztz)) {
                alert('所填总补助不能大于计划总补助，请认真核对');
                return;
            }

            loadjzt();

            $.ajax({
                type:'post',
                url:'/jxcsxm/shares/insertOrUpdateShqx.do',
                data:zj,
                dataType:'json',
                success:function(data){
                    disLoadjzt();
                    alert("保存成功！");
                    parent.$("#grid").datagrid('reload');
                    parent.getdwTj();
                    parent.parent.$("#grid").datagrid('reload');
                    parent.parent.loadTj();
                    closeWindow();
                }
            });
        }

        function search() {
            var params = {
                'gydwdm': $.cookie("unit"),
                'jhxdwh':$("#jhxdwh").combo('getValue')
            }
            $.ajax({
                type:'post',
                async:false,
                url:'/jxcsxm/shares/queryZjByGydwdm.do',
                data:params,
                dataType:'json',
                success:function(data){
                    if (data.ztz == 0) {
                        alert('没有可以分配的计划资金！');
                        return;
                    }
                    $("#funds_num").text(data.ztz);
                }
            });
        }

        function params(name){
            var zj = {
                gydwdm: "", parent: "", dwyf: "",
                cgs1: "", rys1: "", ttc1: "", // 车购税  燃油税  厅统筹
                dfzc1: "", dszc1: "", qxzc1: "", qtzc1:"", // 地方自筹 财政自筹 县区财政  其他自筹
                ztz1:"", bd:"", jhxdwh:"", xmdj:"",
                nf:"", tbsj:"",ztz:"",gydw:""
            };
            var tr = $("tr[name='"+name+"']");
            var ztz1=0;var cgs1=0;var rys1=0;
            var ttc1=0;var dfzc1=0;var dszc1=0;
            var qxzc1=0;var qtzc1=0;
            var ztz = 0;
            $.each(tr, function (index, item) {
                var inputList = $("#"+item.id+" input");
                var trList = $("#"+item.id+" td");
                if (index == 0) {
                    zj.gydwdm = item.id;
                    zj.gydw = $(trList[0]).text();
                    zj.parent = $(inputList[4]).val();
                    zj.dwyf = $("#dwyf").combo('getValue');
                    cgs1 = $(inputList[0]).val() == "" || $(inputList[0]).val() == null ?
                        0 : parseFloat($(inputList[0]).val()); // 车购税
                    rys1 = $(inputList[1]).val() == "" || $(inputList[1]).val() == null ?
                        0 : parseFloat($(inputList[1]).val()); // 燃油税
                    ttc1 = $(inputList[2]).val() == "" || $(inputList[2]).val() == null ?
                        0 : parseFloat($(inputList[2]).val()); // 厅统筹
                    dszc1 = $(inputList[5]).val() == "" || $(inputList[5]).val() == null ?
                        0 : parseFloat($(inputList[5]).val()); // 地方财政
                    qxzc1 = $(inputList[6]).val() == "" || $(inputList[6]).val() == null ?
                        0 : parseFloat($(inputList[6]).val()); // 县区财政
                    qtzc1 = $(inputList[7]).val() == "" || $(inputList[7]).val() == null ?
                        0 : parseFloat($(inputList[7]).val()); // 其他自筹
                    dfzc1 = dszc1 + qxzc1 + qtzc1;
                    zj.cgs1 = cgs1;zj.rys1 = rys1;zj.ttc1 = ttc1;
                    zj.dfzc1 = dfzc1;zj.dszc1 = dszc1;zj.qxzc1 = qxzc1;
                    zj.qtzc1 = qtzc1;
                    ztz1 = cgs1 + rys1 + ttc1 + dfzc1;
                    zj.ztz1 = ztz1;
                    ztz = ztz1;
                    zj.bd = "没有";
                    zj.xmdj = "国省道";
                    zj.jhxdwh = $("#jhxdwh").combo('getValue');
                    zj.nf = $("#nf1").combo('getValue');
                    zj.tbsj = $("#tbsj").datebox("getValue");
                } else {
                    zj.gydwdm += "," + item.id;
                    zj.gydw += "," + $(trList[0]).text();
                    zj.parent += "," + $(inputList[4]).val();
                    zj.dwyf += "," + $("#dwyf").combo('getValue');
                    cgs1 = $(inputList[0]).val() == "" || $(inputList[0]).val() == null ?
                        0 : parseFloat($(inputList[0]).val()); // 车购税
                    rys1 = $(inputList[1]).val() == "" || $(inputList[1]).val() == null ?
                        0 : parseFloat($(inputList[1]).val()); // 燃油税
                    ttc1 = $(inputList[2]).val() == "" || $(inputList[2]).val() == null ?
                        0 : parseFloat($(inputList[2]).val()); // 厅统筹
                    dszc1 = $(inputList[5]).val() == "" || $(inputList[5]).val() == null ?
                        0 : parseFloat($(inputList[5]).val()); // 地方财政
                    qxzc1 = $(inputList[6]).val() == "" || $(inputList[6]).val() == null ?
                        0 : parseFloat($(inputList[6]).val()); // 县区财政
                    qtzc1 = $(inputList[7]).val() == "" || $(inputList[7]).val() == null ?
                        0 : parseFloat($(inputList[7]).val()); // 其他自筹
                    dfzc1 = dszc1 + qxzc1 + qtzc1;
                    zj.cgs1 += "," + cgs1;
                    zj.rys1 += "," + rys1;
                    zj.ttc1 += "," + ttc1;
                    zj.dfzc1 += "," + dfzc1;
                    zj.dszc1 += "," + dszc1;
                    zj.qxzc1 += "," + qxzc1;
                    zj.qtzc1 += "," + qtzc1;
                    ztz1 = cgs1 + rys1 + ttc1 + dfzc1;
                    ztz += ztz1;
                    zj.ztz1 += "," + ztz1;
                    zj.bd += "," + "没有";
                    zj.xmdj += "," + "国省道";
                    zj.jhxdwh += "," + $("#jhxdwh").combo('getValue');
                    zj.nf += "," + $("#nf1").combo('getValue');
                    zj.tbsj += "," + $("#tbsj").datebox("getValue");
                }
            });
            zj.ztz = ztz;
            return zj;
        }
    </script>
</head>
<body>
    <div style="text-align: left;font-size: 12px;margin: 0px;width:99%;">
    <table width="99%" border="0" style="margin-top: 1px; margin-left: 1px;" cellspacing="0" cellpadding="0">

        <tr>
            <td>
                <div align="center">
                    <table class="table1" cellpadding="0" cellspacing="0" width="800">
                        <tr align='center' height="28">
                            <td width="100">年份</td>
                            <td  align="left" style="padding-left: 10px;" width="100">
                                <input type="text" class='easyui-combobox' id='nf1' style="width: 145px;">
                            <td width="100">计划下达文号</td>
                            <td align="left" style="padding-left: 10px;" width="100"><input type='text' id='jhxdwh'style="width: 145px;"></td>
                        </tr>

                        <tr align='center' height="28">
                            <td width="100">到位月份</td>
                            <td align="left" style="padding-left: 10px;" width="100">
                                <input type="text" class='easyui-combobox' id='dwyf' style="width: 120px;">
                            <td align="left" style="padding-left: 10px;" colspan="2">
                                <input value=" 查询  " onclick="search()" style="text-align: center;" type="button"/><font color="red" id="funds_id">
                            *选择计划下达文号后点击查询自动计算剩余资金[<i id="funds_num">0</i>万元]</font>
                            </td>
                        </tr>
                        <tr align='center' height="28">
                            <td width="100">填报时间</td>
                            <td align="left" style="padding-left: 10px;" width="100">
                                <input type='text' class='easyui-datebox' id='tbsj'style="width: 145px;" readonly="readonly">
                            </td>
                            <td width="100"></td>
                            <td align="left" style="padding-left: 10px;" width="100">
                            </td>
                        </tr>
                    </table>
                    <table id="zjdw_table" width="800" class="table" cellpadding="0" cellspacing="0">

                        <tr align='center' height="28">
                            <td>单位名称</td>
                            <td>车购税(万元)</td>
                            <td>燃油税(万元)</td>
                            <td>厅统筹(万元)</td>
                            <td>地方自筹(万元)</td>
                            <td>地市财政自筹(万元)</td>
                            <td>区县财政自筹(万元)</td>
                            <td>其他自筹(万元)</td>
                        </tr>
                        <tbody id="zjdw_table_tbody"></tbody>
                    </table>
                    <table width="600">
                        <tr align="center">
                            <td>
                                <input value=" 保  存  " onclick="save()" style="text-align: center;" type="button"/>
                            </td>
                        </tr>
                    </table>
                </div>
            </td>
        </tr>
    </table>
</div>
</body>
</html>
